import React from "react"
import "./style.less"
import LocateHead from "../../../components/home_components/Locate/LocateHead"
import HotCityList from "../../../components/home_components/Locate/HotCityList"

import { withRouter } from "react-router-dom"
import { connect } from "react-redux"
import { bindActionCreators } from "redux"
import * as cityActions from "../../../redux/actions/city"
import * as webSession from "../../../WebSession"
import * as key from "../../../WebSession/key"

class Locate extends React.Component{
    // constructor(){
    //     super();
       
    // }

    getCityName(value){
        // 把城市名存到redux和本地中
        // console.log(value)
        this.props.cityActions.city({
            cityName: value
        })
        console.log(this.props.city)
        webSession.setLocalMsg(key.CITY_NAME,value);   //存到本地中

    }
    render (){
        // let { cityName } = this.state;
        return (
            <div className="locate-container">
                <LocateHead history={this.props.history}/>
                <div>
                    <h3 className="locate-title">当前定位</h3>
                    <div className="locate-city-name">{this.props.city.cityName}</div>
                </div>
                <HotCityList getCityName={this.getCityName.bind(this)}/>
            </div>
        )
    }
}
// --------redux-------------

function mapStateToProps(state){
    return {
      city: state.cityinfo
    }
  }
  function mapDispatchToProps(dispatch){
    return {
      cityActions: bindActionCreators(cityActions,dispatch)
    }
  }
  
  export default withRouter(connect(
    mapStateToProps,
    mapDispatchToProps
  )(Locate))
